<template>
  <div>
    <el-dropdown>
      <div>
        <i class="fa fa-language" style="font-size: 2.4rem"></i>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item @click="selectChange('zh-cn')">
            <span :style="{color: language === 'zh-cn' ? '#999' : '#333'}">中文</span>
          </el-dropdown-item>
          <el-dropdown-item @click="selectChange('en')">
            <span :style="{color: language === 'en' ? '#999' : '#333'}">English</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script lang="ts">
  import {defineComponent, computed, getCurrentInstance} from 'vue'
  import {useStore} from 'vuex'
  export default defineComponent({
    name: "LanguageSelect",
    setup(){
      const store = useStore()
      // @ts-ignore
      const { ctx } = getCurrentInstance();
      const selectChange = (e: string):void => {
        ctx.$i18n.locale = e
        store.commit('setLanguage',e)
      }
      return{
        language: computed(() => {
          return store.state.app.language
        }),
        selectChange
      }
    },
  })
</script>

<style scoped>

</style>
